<?php 
namespace app\models;

use yii;
use yii\db\Query;

class Product_pay 
{
    private $table;

    public function __construct()
    {
        $this->table = yii::$app->db->tablePrefix.'product_pay';
    }

    public function get_product_pay_list_by_month($where)
    {
       $db = new Query();
       $db->select('sum(need_pay) as need_pay,sum(have_pay) as have_pay,purchase,purchase_order,group_concat(product) as product')
       ->from($this->table)
       ->where(["substr(purchase_order,3,4)"=>$where['m']]);
       if($where['saleman']) {
           $db->andWhere(['purchase'=>$where['saleman']]);
       }
       return $db->groupBy("purchase_order")->all();

    }
}